package com.topscomm.gpm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description TODO
 * @Classname ConvertTimeUtil
 * @Date 2021/12/14
 * @Created by jiangtao
 */
public class ConvertTimeUtil {
	private final static String[] format1 = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
	private final static String[] format2 = {"零","一","二","三","四","五","六","七","八","九"};
	private final static String[] format3 = {"〇","一","二","三","四","五","六","七","八","九"};

	public static String dataToUpper1(String dateString) {
		return dataToUpper(dateString, format1);
	}
	public static String dataToUpper2(String dateString) {
		return dataToUpper(dateString, format2);
	}
	public static String dataToUpper3(String dateString) {
		return dataToUpper(dateString, format3);
	}
	/**
	 * @Description:     日期转化为大小写
	 * @Author:         mengmeng
	 * @Date:           2021/8/11 11:11
	 * @Version:        1.0
	 */
	public static String dataToUpper(String dateString, String[] format) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date dateTime = null;
		try {
			dateTime = simpleDateFormat.parse(dateString);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar ca = Calendar.getInstance();
		ca.setTime(dateTime);
		int year = ca.get(Calendar.YEAR);
		int month = ca.get(Calendar.MONTH) + 1;
		int day = ca.get(Calendar.DAY_OF_MONTH);
		return numToUpper(year, format) + "年" + monthToUppder(month, format) + "月" + dayToUppder(day, format) + "日";
	}

	/**
	 * @Description:    将数字转化为大写（字体格式可自己定义）
	 * @Date:           2021/8/11 11:11
	 * @Version:        1.0
	 */
	public static String numToUpper(int num, String[] format) {
		char[] str = String.valueOf(num).toCharArray();
		String rstr = "";
		for (int i = 0; i < str.length; i++) {
			rstr = rstr + format[Integer.parseInt(str[i] + "")];
		}
		return rstr;
	}

	/**
	 * @Description:    月转化为大写
	 * @Author:         mengmeng
	 * @Date:           2021/8/11 11:11
	 * @Version:        1.0
	 */
	public static String monthToUppder(int month, String[] format) {
		if(month < 10) {
			return numToUpper(month, format);
		} else if(month == 10){
			return "十";
		} else {
			return "十" + numToUpper(month - 10, format);
		}
	}

	/**
	 * @Description:    日转化为大写
	 * @Author:         mengmeng
	 * @Date:           2021/8/11 11:10
	 * @Version:        1.0
	 */
	public static String dayToUppder(int day, String[] format) {
		if(day < 20) {
			return monthToUppder(day, format);
		} else {
			char[] str = String.valueOf(day).toCharArray();
			if(str[1] == '0') {
				return numToUpper(Integer.parseInt(str[0] + ""), format) + "十";
			}else {
				return numToUpper(Integer.parseInt(str[0] + ""), format) + "十" + numToUpper(Integer.parseInt(str[1] + ""), format);
			}
		}
	}
}
